home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1997-10-26 | 4.7 KB | 145 lines |
- (*----------------------------------------------------------------------*
- * *
- * MAGICTOOLS Modula's All purpose GEM Interface Cadre Toolbox *
- * ÿ ÿ ÿ ÿ ÿ *
- *----------------------------------------------------------------------*
- * Version 3.30 02.02.1992 (C)90/91/92 by Peter Hellinger Software *
- *----------------------------------------------------------------------*
- * Dieses Modul ist urheberrechtlich geschtzt. *
- * *
- * Die Verffentlichung des Quelltextes oder Teilen daraus, sowie die *
- * Verbreitung des bersetzten, nicht gelinkten Codes in schriftlicher, *
- * oder maschinenlesbarer Form, insbesondere in Zeitschriften, Mail- *
- * boxen oder anderen Medien bedarf der ausdrcklichen schriftlichen *
- * Einverstndnisserklrung des Autors. *
- * *
- * Die Verbreitung des Moduls als Teil eines gelinkten Programms ist *
- * fr Lizenznehmer ausdrcklich erlaubt! Der Autor behlt sich das *
- * Recht vor, diese Erlaubnis jederzeit und ohne Angaben von Grnden zu *
- * widerrufen. *
- *----------------------------------------------------------------------*)
-
- IMPLEMENTATION MODULE mtProcess;
-
- (*----------------------------------------------------------------------*
- * Int. Vers | Datum | Name | nderung *
- *-----------+----------+------+----------------------------------------*
- * 3.00 | 18.01.92 | Hp | *
- *-----------+----------+------+----------------------------------------*)
-
-
-
- (* IMPLEMENTATION FR >>> Megamax-Modula-2 <<< *)
- (* *)
- (*$R- Range-Checks *)
- (*$S- Stack-Check *)
- (* *)
- (*----------------------------------------------*)
-
-
-
-
-
-
- FROM MagicSys IMPORT Nil, Null, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6,
- Bit7, Bit8, Bit9, Bit10, Bit11, Bit12, Bit13, Bit14,
- Bit15, LOC, Byte, ByteSet, sWORD, sINTEGER, sCARDINAL,
- sBITSET, lINTEGER, lCARDINAL, lWORD, lBITSET,
- CastToChar, CastToByte, CastToByteset, CastToInt,
- CastToCard, CastToBitset, CastToWord, CastToLInt,
- CastToLCard, CastToLBitset, CastToLWord, CastToAddr,
- TosVersion, Accessory, Basepage, SysHeader, TosDate;
-
-
-
-
-
-
-
-
- FROM Storage IMPORT ALLOCATE, DEALLOCATE;
-
-
-
-
- FROM SYSTEM IMPORT ADDRESS, NEWPROCESS, TRANSFER, TSIZE;
-
- TYPE SIGNAL = POINTER TO PROCESS;
- PROCESS = RECORD
- next: SIGNAL;
- queue: SIGNAL;
- core: ADDRESS;
- ready: BOOLEAN;
- END;
-
- VAR currProcess: SIGNAL;
-
- PROCEDURE StartProcess (p: PROC; n: lCARDINAL);
- VAR s0: SIGNAL;
- workSpace: ADDRESS;
- BEGIN
- s0:= currProcess;
- ALLOCATE (workSpace, n);
- ALLOCATE (currProcess, TSIZE (PROCESS));
- WITH currProcess^ DO
- next:= s0^.next;
- s0^.next:= currProcess;
- ready:= TRUE;
- queue:= NIL;
- END;
- NEWPROCESS (p, workSpace, n, currProcess^.core);
-
- TRANSFER (s0^.core, currProcess^.core);
- END StartProcess;
-
- PROCEDURE SEND (VAR s: SIGNAL);
- VAR s0: SIGNAL;
- BEGIN
- IF s # NIL THEN
- s0:= currProcess; currProcess:= s;
- WITH currProcess^ DO
- s:= queue; ready:= TRUE; queue:= NIL;
- END;
- TRANSFER (s0^.core, currProcess^.core);
- END;
- END SEND;
-
- PROCEDURE WAIT (VAR s: SIGNAL);
- (* fuege currProcess in die Schlange (queue) ein *)
- VAR s0, s1: SIGNAL;
- BEGIN
- IF s = NIL THEN
- s:= currProcess;
- ELSE
- s0:= s; s1:= s0^.queue;
- WHILE s1 # NIL DO s0:= s1; s1:= s0^.queue; END;
- s0^.queue:= currProcess;
- END;
- s0:= currProcess;
- REPEAT
- currProcess:= currProcess^.next;
- UNTIL currProcess^.ready;
- IF currProcess = s0 THEN HALT; END; (* Deadlock sollte nicht sein aber... *)
- s0^.ready:= FALSE;
- TRANSFER (s0^.core, currProcess^.core);
- END WAIT;
-
- PROCEDURE Awaited (s: SIGNAL): BOOLEAN;
- BEGIN
- RETURN s # NIL;
- END Awaited;
-
- PROCEDURE InitSignal (VAR s: SIGNAL);
- BEGIN
- s:= NIL;
- END InitSignal;
-
- BEGIN
- ALLOCATE (currProcess, TSIZE (PROCESS));
- WITH currProcess^ DO
- next:= currProcess;
- ready:= TRUE;
- queue:= NIL;
- END;
- END mtProcess.
-